package PTA_JAVA.JavaB.Javademo7;
import java.util.*;
import java.util.stream.Collectors;

public class Main {
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        String s= sc.nextLine();
        ArrayList<String> nameList = new ArrayList<String>();
        while(!s.equals("end")){
            nameList.add(s);
            s= sc.nextLine();
        }
        nameList= (ArrayList<String>) nameList.stream().distinct().collect(Collectors.toList());
        System.out.println(nameList);
        int i = Integer.parseInt(sc.nextLine());
        s = sc.nextLine();
        nameList.add(i,s);
        int j = Integer.parseInt(sc.nextLine());
        nameList.remove(j);

        System.out.println(nameList.toString());

        String name1 = sc.nextLine();
        String name2 = sc.nextLine();

        int k=nameList.indexOf(name1);
        System.out.println("k="+k);
        if(k>=0){
            nameList.set(k, name2);
        }else if(k==-1){
            nameList.add(name2);
        }
        System.out.println(nameList);

    }
}
